package com.ruoyi.xzs.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xzs.domain.Paper;
import com.ruoyi.xzs.service.IPaperService;
import com.ruoyi.xzs.vo.PaperVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 卷库管理Controller
 * 
 * @author li
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/paper")
public class PaperController extends BaseController
{
    @Autowired
    private IPaperService paperService;

    /**
     * 查询卷库管理列表
     */
    @RequiresPermissions("xzs:paper:list")
    @GetMapping("/list")
    public TableDataInfo list(PaperVO paper)
    {
        startPage();
        List<PaperVO> list = paperService.selectPaperList(paper);
        return getDataTable(list);
    }

    /**
     * 导出卷库管理列表
     */
    @RequiresPermissions("xzs:paper:export")
    @Log(title = "卷库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperVO paper)
    {
        List<PaperVO> list = paperService.selectPaperList(paper);
        ExcelUtil<PaperVO> util = new ExcelUtil<PaperVO>(PaperVO.class);
        util.exportExcel(response, list, "卷库管理数据");
    }

    /**
     * 获取卷库管理详细信息
     */
    @RequiresPermissions("xzs:paper:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paperService.selectPaperById(id));
    }

    /**
     * 新增卷库管理
     */
    @RequiresPermissions("xzs:paper:add")
    @Log(title = "卷库管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PaperVO paperVO)
    {
        return toAjax(paperService.insertPaper(paperVO));
    }

    /**
     * 修改卷库管理
     */
    @RequiresPermissions("xzs:paper:edit")
    @Log(title = "卷库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Paper paper)
    {
        return toAjax(paperService.updatePaper(paper));
    }

    /**
     * 删除卷库管理
     */
    @RequiresPermissions("xzs:paper:remove")
    @Log(title = "卷库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperService.deletePaperByIds(ids));
    }

}
